import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class submitOrderCartL extends StatefulWidget {
  submitOrderCartL(
      {Key key,
      this.commodityId,
      this.commodityNumber,
      this.commodityNumberFun,
      this.imgurl1,
      this.money,
      this.intro,
      this.name})
      : super(key: key);
  int commodityId;
  String intro;

  String name;
  var money;
  int commodityNumber;
  String imgurl1;
  ValueChanged<List> commodityNumberFun;

  @override
  _submitOrderCartLState createState() => _submitOrderCartLState();
}

class _submitOrderCartLState extends State<submitOrderCartL> {

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.fromLTRB(16, 0, 16, 16),
      padding: EdgeInsets.all(12),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(10)),
      child: Column(
        children: [
          Row(
            children: [
              Container(
                margin: EdgeInsets.only(right: 8),
                child: Image.asset(
                  'assets/images/common/logo.png',
                  width: 20,
                ),
              ),
              Text(
                'NEST店铺',
                style: TextStyle(color: Colors.grey[800]),
              )
            ],
          ),
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                  margin: EdgeInsets.only(right: 10),
                  width: 110,
                  child:
                      Image.network(widget.imgurl1)
                      ),
                      
                      // Image.network(
                      //     'http://xiangrikui.resource.vaiwan.com/2021/07/21/b6707132-3168-4fea-ab35-4b024a80c120.png')),
              
              Container(
                  margin: EdgeInsets.only(right: 5),
                  width: 140,
                  child: Text(
                    widget.intro,
                    // '12',
                    maxLines: 5,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(fontSize: 12, color: Colors.grey[800]),
                  )),
              Center(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.end,
                  children: [
                    Text(
                      '￥${widget.money}',
                      // '123',
                      style:
                          TextStyle(fontSize: 10, color: Colors.blueGrey[800]),
                    ),
                    Text(
                      'x${widget.commodityNumber}',
                      // '12',
                      style:
                          TextStyle(fontSize: 10, color: Colors.blueGrey[800]),
                    )
                  ],
                ),
              )
            ],
          ),
          Padding(
            padding: EdgeInsets.fromLTRB(0, 8, 0, 0),
            child: Row(
              children: [
                Text('购买数量'),
                Spacer(),
                Container(
                  width: 80,
                  padding: EdgeInsets.fromLTRB(8, 6, 8, 6),
                  decoration: BoxDecoration(
                      color: Colors.grey[50],
                      borderRadius: BorderRadius.circular(10)),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      InkWell(
                        onTap: () {
                          sum();
                        },
                        child: Container(
                            padding: EdgeInsets.all(3),
                            decoration: BoxDecoration(
                                color: Colors.grey[50],
                                borderRadius: BorderRadius.circular(2),
                                boxShadow: [
                                  BoxShadow(
                                      color: Colors.grey[400],
                                      blurRadius: 4,
                                      spreadRadius: 0)
                                ]),
                            child: Icon(Icons.remove)),
                      ),
                      Text('${widget.commodityNumber}'),
                      // Text('123'),
                      InkWell(
                        onTap: () {
                          add();
                        },
                        child: Container(
                            padding: EdgeInsets.all(3),
                            decoration: BoxDecoration(
                                color: Colors.grey[50],
                                borderRadius: BorderRadius.circular(2),
                                boxShadow: [
                                  BoxShadow(
                                      color: Colors.grey[400],
                                      blurRadius: 4,
                                      spreadRadius: 0)
                                ]),
                            child: Icon(Icons.add)),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          Padding(
            padding: EdgeInsets.fromLTRB(0, 8, 0, 0),
            child: Row(
              children: [
                Text('配送方式'),
                Container(
                  margin: EdgeInsets.only(left: 16),
                  child: Text(
                    '普通配送',
                    style: TextStyle(fontSize: 12, color: Colors.grey[700]),
                  ),
                ),
                Spacer(),
                Text('随机快递')
              ],
            ),
          ),
          Row(
            children: [
              Text(
                '共${widget.commodityNumber}件',
                // '共1件',
                style: TextStyle(color: Colors.grey[700], fontSize: 13),
              ),
              Container(
                margin: EdgeInsets.fromLTRB(8, 0, 4, 0),
                child: Text(
                  '小计:',
                  style: TextStyle(),
                ),
              ),
              Text(
                '￥${widget.commodityNumber * widget.money}',
                // '￥1',
                style: TextStyle(color: Colors.deepOrange[700]),
              )
            ],
          )
        ],
      ),
    );
  }

  add() {
    widget.commodityNumber++;
    // print(widget.commodityNumber);
    change();
    setState(() {});
  }

  sum() {
    if (widget.commodityNumber == 1) {
      return;
    }
    widget.commodityNumber--;
    change();
    setState(() {});
  }

  void change() {
    List huidiaolist = [widget.commodityId, widget.commodityNumber];

    widget.commodityNumberFun(huidiaolist);
  }
}
